import React from 'react'
//引入仓库store
import store from '../../store/store'
//引入不好拼写的名字
import { incrementAction,decrementAction,waitIncrementAction } from '../../store/actions/countAction'

export default function Count() {
  //获取store仓库中的数据
  const {count} = store.getState().count
  const {movieList} = store.getState().movie
    const incrementHandle = ()=>{
      //dispatch向store中发送数据
      store.dispatch(incrementAction(1))
    }

    const decreamentHandle = ()=>{
      store.dispatch(decrementAction(1))

    }

    const ifOddDecrementHandle = ()=>{
      if (count %2 !==0){
        store.dispatch(incrementAction(1))
      }
    }

    const waitDecrementHandle = ()=>{
      store.dispatch(waitIncrementAction(1))
    }



  return (
    <div>
        <h1>我是Count组件 我的值是{count}</h1>
        <h2>当前电影总数是{movieList.length}</h2>
        <div>
            <button onClick={incrementHandle}>累加</button>
            <button onClick={decreamentHandle}>累减</button>
            <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
            <button onClick={waitDecrementHandle}>等2s再加1</button>
        </div>
    </div>
  )
}
